
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFiMulti.h>
 
// 测试HTTP请求用的URL。注意网址前面必须添加"http://"
#define URL "http://www.example.com"
 
ESP8266WiFiMulti multi;

void setup() {
  Serial.begin(9600);
  multi.addAP("MERCURY_394B46", "wifi19900509wifi"); 
  multi.addAP("wsm", "WSM19900509"); 
  while (multi.run() != WL_CONNECTED) {
    delay(1000);
    Serial.print(".");
  }
  Serial.print("WiFi Connected!");
  Serial.println(WiFi.localIP());

  
  httpClientRequest();  
}
 
void loop() {}
 
void httpClientRequest(){
 
 //httpClient 已经过时，应该和WiFiClient一起使用或单独使用WiFiClient
  HTTPClient httpClient;
  WiFiClient wifiClient;
 
  httpClient.begin(wifiClient,URL); 
  Serial.print("URL: "); Serial.println(URL);

  int httpCode = httpClient.GET();
  // HTTP_CODE_OK =200
  if (httpCode == HTTP_CODE_OK) {
    String responsePayload = httpClient.getString();
    Serial.println(responsePayload);
  } else {
    Serial.println("Server Respose Code:");
    Serial.println(httpCode);
  }
 
  // 关闭ESP8266与服务器连接
  httpClient.end();
}